home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / ipc / sub_clifd.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  740b  |  37 lines

  1. #include    <stdio.h>
  2.  
  3. #define    MAXBUFF        1024
  4.  
  5. client(readfd, writefd)
  6. int    readfd;
  7. int    writefd;
  8. {
  9.     char    buff[MAXBUFF];
  10.     int    n;
  11.  
  12.     /*
  13.      * Read the filename from standard input,
  14.      * write it to the IPC descriptor.
  15.      */
  16.  
  17.     if (fgets(buff, MAXBUFF, stdin) == NULL)
  18.         err_sys("client: filename read error");
  19.  
  20.     n = strlen(buff);
  21.     if (buff[n-1] == '\n')
  22.         n--;            /* ignore newline from fgets() */
  23.     if (write(writefd, buff, n) != n)
  24.         err_sys("client: filename write error");;
  25.  
  26.     /*
  27.      * Read the data from the IPC descriptor and write
  28.      * to standard output.
  29.      */
  30.  
  31.     while ( (n = read(readfd, buff, MAXBUFF)) > 0)
  32.         if (write(1, buff, n) != n)    /* fd 1 = stdout */
  33.             err_sys("client: data write error");
  34.     if (n < 0)
  35.         err_sys("client: data read error");
  36. }
  37.